import http from '@/utils/request'

import config from '@/config'


import { SiteStore } from '@/stores/site'


function fullurl(webdo) {
 let site = SiteStore(); 
  if (webdo.indexOf('http') === 0) {
      return webdo
    }
    if (webdo.indexOf('/') === 0) {
      return `${config.api_url}${webdo}`
    }

    var url = `${config.api_url}${config.prefix}/${site.mident}/wapp/${webdo}`
    return url


 
}

async function get(webdo, params = {}, config = {}, onlydata = true) {
  if (typeof webdo != 'string') {
    params = webdo

    webdo = params['webdo']
  }

  var url = fullurl(webdo)
  return await http.get(url, params, config, onlydata)
}
async function post(webdo, params = {}, config = {}, onlydata = true) {
  if (typeof webdo != 'string') {
    params = webdo

    webdo = params['webdo']
  }
  var url = fullurl(webdo)

  return await http.post(url, params, config, onlydata)
}
export default {
  get: get,
  post: post,
  edit: {
    name: '详情页操作',
    add: async function (webdo, para) {
      para['op'] = 'save'
      return await post(webdo, para)
    },
    get: async function (webdo, para) {
      para['op'] = 'edit'
      return await get(webdo, para)
    }
  },
  list: {
    page: async function (webdo, para) {
      if (!para['offset']) {
        para['offset'] = 0
      }
      if (!para['limit']) {
        para['limit'] = 15
      }

      return await post(webdo, para)
    }
  }
}
